<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/heard.jsp"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>在此处插入标题</title>


<script type="text/javascript">
  var list_url="${basePath}article/admin/toArticleUI.shtml";
	function doAddUI(){
		document.forms[0].action = "${basePath}article/admin/toAddUI.shtml";
  		document.forms[0].submit();
	}
	function doSerach(){
		$("#pageNo").val(0);
		document.forms[0].action = "${basePath}article/admin/toArticleUI.shtml";
  		document.forms[0].submit();
	}
	function doEdit(id){
		
		document.forms[0].action = "${basePath}article/admin/doEditUI.shtml?id="+id;
  		document.forms[0].submit();
	}
	//删除
	function doDelete(id){
		document.forms[0].action = "${basePath}article/admin/deleteArticle.shtml?id="+id;
  		document.forms[0].submit();
	}
	//全选和全反选
	function doSelectAll(){
		if($("#selAll").is(':checked')){
			
			$("input:checkbox").attr("checked", true);  
		}else{
			
			$("input:checkbox").attr("checked", false);
		}
	}
	//删除全部
	function doDelereAll(){
		document.forms[0].action = "${basePath}article/admin/deleteAllArticle.shtml";
  		document.forms[0].submit();
	}
	//发布和停用
	function doPublic(id,state){
		
		$.ajax({
			url:"${basePath}article/admin/upadteStateArticle.shtml",
			data:{"id":id,"state":state},
			type:"post",
			success:function(msg){
				if("更新状态成功" ==msg){
					if(state== 1){
						$("#show_"+id).html("发布");
						$("#oper_"+id).html('<a href="javascript:doPublic(\''+id+'\',0)">停用</a>');
					} else {
						$("#show_"+id).html("停用");
					
						$("#oper_"+id).html('<a href="javascript:doPublic(\''+id+'\',1)">发布</a>');
					  }
					}else{
					alert("更新状态失败");
				}
			},
			error:function(){
				alert("更新状态失败");
			}
		});
	}
</script>
</head>
<body>

	<div class="container-fluid">
		<form action="" method="post">
			<!-- 第一行 -->
			<div class="row">
				<div class="col-md-4">
					<div class="input-group " style="margin-top: 0px positon:relative">
						<input type="text" name="serach" class="form-control"
							placeholder="请输入文章标题"/ > <span class="input-group-btn">
							<button class="btn btn-info btn-search" onclick="doSerach()">查找</button>
						</span>

					</div>
				</div>
				<div class="col-md-4">
					<input class="btn btn-info" type="button" value="添加"
						onclick="doAddUI()">
				</div>
				</li>
				<div class="col-md-4">
					<input class="btn btn-info" type="button" value="删除" onclick="doDelereAll()">
				</div>
				</li>
			</div>
			<div class="row">
				<table class="table table-bordered">
					<tr class="info">
						<td width="30" align="center"><input type="checkbox"
							id="selAll" onclick="doSelectAll()"  /></td>
						<th align="center">文章标题</th>
						<th width="120">文章分类</th>
						<th width="120">创建人</th>
						<th width="140">创建时间</th>
						<th width="80">状态</th>
						<th width="120">操作</th>
					</tr>
					<c:forEach items="${page.itmes }" var="article">
						<tr>
							<td align="center"><input type="checkbox" name="selectedRow"
								value="${article.id }" /></td>
							<td align="center">${article.title }</td>
							<td align="center"><c:forEach var="articletype"
									items="${articleType }">
									<c:if test="${articletype.key ==article.type }">${articletype.value }</c:if>
								</c:forEach></td>
							<td align="center">${article.create }</td>
							<td align="center"><fmt:formatDate
									value="${article.modifyTime }" pattern="yyyy-MM-dd HH:mm:ss" /></td>
							<td id="show_${article.id }" align="center"><c:if
									test="${article.state ==0 }">停用</c:if> <c:if
									test="${article.state ==1 }">发布</c:if></td>
							<td align="center"><span id="oper_${article.id }"> <c:if
										test="${article.state ==1 }">
										<a href="javascript:doPublic('${article.id }',0)">停用</a>
									</c:if> <c:if test="${article.state ==0 }">
										<a href="javascript:doPublic('${article.id }',1)">发布</a>
									</c:if>
							</span> <a href="javascript:doEdit('${article.id }')">编辑</a> <a
								href="javascript:doDelete('${article.id }')">删除</a></td>
						</tr>


					</c:forEach>
				</table>
			</div>
			<jsp:include page="/common/page.jsp"></jsp:include>
		</form>
</body>
</html>